cmake_minimum_required(VERSION 3.5)

# 设置C编译器为clang
set(CMAKE_C_COMPILER "clang")
# 设置C++编译器为clang++
set(CMAKE_CXX_COMPILER "clang++")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wvla-cxx-extension")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-c-typedef-for-linkage")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wenum-constexpr-conversion")

message(STATUS "C   Compiler:${CMAKE_C_COMPILER}")
message(STATUS "C++ Compiler:${CMAKE_CXX_COMPILER}")

project(demo_clangtidy CXX)

set(CMAKE_BUILD_TYPE Debug)

message(STATUS "ProjectName:${PROJECT_NAME}")
message(STATUS "ProjectSourceDir:${PROJECT_SOURCE_DIR}")

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
check_include_file_cxx(coroutine HAS_COROUTINE)
if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
    # Do nothing
elseif (HAS_ANY AND HAS_STRING_VIEW AND HAS_COROUTINE)
    set(CMAKE_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
    set(CMAKE_CXX_STANDARD 17)
else ()
    set(CMAKE_CXX_STANDARD 14)
endif ()

# 设置打印编译过程
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#add_executable(${PROJECT_NAME} main.cc)

set(CLANG_TIDY_COMMAND clang-tidy;
            -header-filter=^${PROJECT_SOURCE_DIR}/.*;
            -config-file=${PROJECT_SOURCE_DIR}/.clang-tidy;)
set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND})
message(STATUS "CMAKE_CXX_CLANG_TIDY:${CMAKE_CXX_CLANG_TIDY}")

add_executable(${PROJECT_NAME} main.cc)

set_target_properties(${PROJECT_NAME}
            PROPERTIES
            CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND})


if (CMAKE_CXX_STANDARD LESS 17)
    message(FATAL_ERROR "c++17 or higher is required")
elseif (CMAKE_CXX_STANDARD LESS 20)
    message(STATUS "use c++17")
else ()
    message(STATUS "use c++20")
endif ()

aux_source_directory(AnnexD AnnexD_SRC)


target_include_directories(${PROJECT_NAME}
                           PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
                                   ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_sources(${PROJECT_NAME}
               PRIVATE
               ${SRC_DIR}
               ${AnnexD_SRC}
               )



